package com.iflytek.springboot_medicine.service;

import com.iflytek.springboot_medicine.entity.Category;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface CategoryRepository extends JpaRepository<Category, Integer> {
    @Query("SELECT u FROM Category u WHERE (:name IS NULL OR u.name LIKE CONCAT('%', COALESCE(:name, ''), '%'))")
    Page<Category> findByName(@Param("name") String name, Pageable pageable);

    @Query("SELECT c.id FROM Category c WHERE c.name = :name")
    Integer findIdByName(@Param("name") String name);
    Category deleteById(int id);
}
